#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <stdlib.h>
#include <string.h>



typedef struct word
{
    char* str;
    int time;
}Word;

char** uncommonFromSentences(char* s1, char* s2, int* returnSize) {
    Word word[200] = { 0 };
    int wordSize = 0;
    char* tmp = strtok(s1, " ");
    int flg = 0;
    int i = 0;
    while (tmp != NULL)
    {
        flg = 0;
        for (i = 0; i < wordSize; i++)
        {
            if (strcmp(word[i].str, tmp) == 0)
            {
                flg = 1;
                break;
            }
        }
        if (flg)
        {
            word[i].time += 1;
        }
        else
        {
            int len = strlen(tmp);
            word[wordSize].str = (char*)malloc(sizeof(char) * (len + 1));
            strcpy(word[wordSize].str, tmp);
            word[wordSize].time += 1;
            wordSize++;
        }
        tmp = strtok(NULL, " ");
    }
    tmp = strtok(s2, " ");
    while (tmp != NULL)
    {
        flg = 0;
        for (i = 0; i < wordSize; i++)
        {
            if (strcmp(word[i].str, tmp) == 0)
            {
                flg = 1;
                break;
            }
        }
        if (flg)
        {
            word[i].time += 1;
        }
        else
        {
            int len = strlen(tmp);
            word[wordSize].str = (char*)malloc(sizeof(char) * (len + 1));
            strcpy(word[wordSize].str, tmp);
            word[wordSize].time += 1;
            wordSize++;
        }
        tmp = strtok(NULL, " ");
    }
    char** ans = (char**)malloc(sizeof(char*) * (101));
    *returnSize = 0;
    for (i = 0; i < wordSize; i++)
    {
        if (word[i].time == 1)
        {
            int len = strlen(word[i].str);
            ans[(*returnSize)] = (char*)malloc(sizeof(char) * (len + 1));
            strcpy(ans[(*returnSize)], word[i].str);
            (*returnSize)++;
        }
    }
    return ans;
}

int main()
{
    int size = 0;
    char s1[] = { "this apple is sweet" };
    char s2[] = { "this apple is sour" };
    char** ret = uncommonFromSentences(s1,s2,&size);
    for (int i = 0; i < size; i++)
    {
        printf("%s ", ret[i]);
    }

    return 0;
}